package gang.org.springframework.framework.core.type.classreading;

import gang.org.springframework.framework.metadata.GangAnnotationMetadata;
import gang.org.springframework.framework.metadata.GangMergedAnnotations;
import gang.org.springframework.framework.type.GangMethodMetadata;

import java.util.*;

/**
 * @author gang.chen
 * @description
 * @Date 2021/8/5 12:55
 */
public class GangSimpleAnnotationMetadata implements GangAnnotationMetadata {

    private final String superClassName;

    private final String className;

    private final String[] memberClassName;

    private final GangMergedAnnotations annotations;

    private final GangMethodMetadata[] annotatedMethods;

    //TODO
    private Set<String> annotationTypes;

    public GangSimpleAnnotationMetadata(String className,
                                        int access,
                                        String enclosingClassName,
                                        String superClassName,
                                        boolean independentInnerClass,
                                        String[] interfaceNames,
                                        String[] memberClassNames,
                                        GangMethodMetadata[] annotatedMethods,
                                        GangMergedAnnotations annotations){
        this.className = className;
        this.memberClassName = memberClassNames;
        this.annotations = annotations;
        this.superClassName = superClassName;
        this.annotatedMethods = annotatedMethods;
    }


    @Override
    public GangMergedAnnotations getAnnotations() {
        return annotations;
    }

    @Override
    public String getClassName() {
        return this.className;
    }

    @Override
    public String[] getMemberClassNames() {
        return this.memberClassName;
    }

    @Override
    public String getSuperClassName() {
        return this.superClassName;
    }

    /**
     * 业务意义 TODO
     * */
    @Override
    public Set<GangMethodMetadata> getAnnotatedMethods(String annotationName) {
        Set<GangMethodMetadata> annotatedMethods = null;
        for (GangMethodMetadata annotatedMethod : this.annotatedMethods) {
            // 业务逻辑 TODO
            if (null == annotatedMethods){
                annotatedMethods = new LinkedHashSet<>(4);
            }
            annotatedMethods.add(annotatedMethod);
        }
        return annotatedMethods != null ? annotatedMethods : Collections.emptySet();
    }

    @Override
    public Set<String> getAnnotationTypes() {

        Set<String> annotationTypes = this.annotationTypes;

        if (annotationTypes == null ) {

            annotationTypes = GangAnnotationMetadata.super.getAnnotationTypes();

            this.annotationTypes = annotationTypes;
        }


        return annotationTypes;
    }
}
